<template>
	<view class="g-cell" 
		@click="handleClick"
		:class="[isTopBoder&&'g-cell-top-border',
				!propBoder&&'g-cell-not-border',
				]"
		>
		<view class="l-wrap">
			<span :class="['iconfont','icon-'+icon ]"
				  class='cell-icon' 
				  :style="{color:iconColor}"></span>
			<text class="l-wrap-title">{{label}}</text>
			<slot name="left"></slot>
		</view>
		<view class="r-wrap">
			<text class="r-wrap-value">{{value}}</text>
			<view class="jiantou-wrap" >
				<span class="jiantou iconfont icon-window-down " v-show="url"></span>
			</view>
			<slot name="right"></slot>
		</view>
	</view>
</template>

<script>
import utils from "../../utils/utils.js"
export default {
	name: 'g-cell',
	data() {
		return {
			cellParent: null,
			isTopBoder:false,//是否有上boder
			propBoder:true,
		};
	},
	props: {
		label:{
			type:String,
		},
		icon:{
			type:String,
		},
		value:{
			type:String,
		},
		url:{
			//点击跳转的地址
			type:String,
		},
		iconColor:{
			type:String,
			default:"#0c8aff"
		},
	},
	computed: {
		Cpu_isTopBoder(){
			if(this.cellParent.cellChild.length==0){
				//当前为第一项
				return true
			}
		},
	},
	methods: {
		handleClick(){
			//若url存在侧直接跳转
			if(this.url){
				uni.navigateTo({
					url:this.url
				})
				this.$emit("click")
			}
		},
		init(){
			this.cellParent = utils.findComponents('g-cell-group', this, '$parent')
			this.propBoder = this.cellParent.border
			if(this.cellParent.cellChild.length==0){
				//当前为第一项
				this.isTopBoder = true
			}
			this.cellParent.cellChild.push(this)
		},
	},
	mounted() {
		this.init()
	},
	created() {}
};
</script>
<style lang="scss" scoped>
	@import "../../theme.scss";
	@import "../../iconfont.css";
	
	.g-cell{
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 88rpx;
		padding: 0 40rpx;
		border-top: 2rpx solid $g-boder-light;
		background: #fff;
		&:hover{
			background:$g-boder-ligier;
		}
		&-top-border{
			border-top: 2rpx solid $g-boder-light;
		}
		&-not-border{
			border: 2rpx solid  #fff !important;
		}
	}
	.l-wrap{
		display: flex;
		align-items: center;
		&title{
			font-weight: 400;
			color: $g-text-darker;
			font-size: 32rpx;
		}
		.cell-icon{
			display: flex;
			align-items: center;
			font-size: 32rpx;
			margin-right: 6rpx;
		}
	}
	.r-wrap{
		display: flex;
		align-items: center;
		&-value{
			font-size: 30rpx;
			color: $g-text-darker;
		}
		.jiantou-wrap{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 30rpx;
			.jiantou{
				display: flex;
				align-items: center;
				justify-content: center;
				height: 20rpx;
				transform:rotate(-90deg);
				font-size: 50rpx;
				color: $g-text-darker;
			}
		}
	}
</style>
